<?php
/**
 * Created by PhpStorm.
 * User: zhendanxu
 * Date: 2019/4/25
 * Time: 2:46 PM
 */

namespace AppBundle\Controller;


use Symfony\Component\HttpFoundation\Request;

class RedirectingController extends BaseController
{

    /**
     * 重定向包含尾斜杠的url
     * @param Request $request
     * @return \Symfony\Component\HttpFoundation\RedirectResponse
     */
    public function removeTrailingSlashAction(Request $request)
    {
        $pathInfo = $request->getPathInfo();
        $requestUri = $request->getRequestUri();

        $url = str_replace($pathInfo, rtrim($pathInfo, ' /'), $requestUri);

        return $this->redirect($url, 301);
    }
}